package com.example.work4

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.example.work4.view.StatusBar
import com.farsunset.cim.sdk.android.CIMPushManager

class MStartActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        StatusBar.setStatusBarAsBlue(window)
        setContentView(R.layout.activity_start)
        checkPermission()
        CIMPushManager.connect(this,"43.142.83.95",23456);
//        TimeUnit.SECONDS.sleep()

    }

    private val permissions = arrayOf<String>(
        Manifest.permission.ACCESS_FINE_LOCATION,
        Manifest.permission.ACCESS_COARSE_LOCATION,
        Manifest.permission.WRITE_EXTERNAL_STORAGE
    )
    private val PERMISSIONS_RESULT_CODE = 121 // 自定义


    /**
     * 申请权限
     */
    private fun checkPermission() {
        // SDK版本 大于或等于23 动态申请权限
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return
        // 检查 未授权 的 权限
        val pl: MutableList<String> = ArrayList()
        for (permission in permissions) {
            if (ContextCompat.checkSelfPermission(this, permission)
                != PackageManager.PERMISSION_GRANTED
            ) {
                pl.add(permission)
            }
        }
        // 申请权限
        if (pl.size > 0) {
            ActivityCompat.requestPermissions(this, pl.toTypedArray(), PERMISSIONS_RESULT_CODE)
        }
        var intent=Intent(applicationContext,LoginActivity::class.java);
        startActivity(intent)
    }
}